angular.module('Service', [])
//获取文章的服务
.service('Article',['$http','$rootScope', function($http,$rootScope){
	return {

		//获取文章分类的
		"fenlei": function(){

			$http.jsonp('http://www.phonegap100.com/appapi.php',{
				"params": {
					"a": "getPortalCate",
					"callback": "JSON_CALLBACK"
				}
			}).then(function(response){
				//通过广播把得到的数据传出去
				$rootScope.$broadcast('fenleiData', response.data.result);
			},function(error){

			})
		},
	
		//获取文章列表
		"list": function(catId,num){
			$http.jsonp('http://www.phonegap100.com/appapi.php',{
				"params": {
					"a": "getPortalList",
					"callback": "JSON_CALLBACK",
					"catid": catId,
					"page": num
				}
			}).then(function(response){
				//通过广播把得到的数据传出去
				$rootScope.$broadcast('list', response.data.result);
			},function(error){

			})
		},
		detail:function(tid){
			$http.jsonp("http://www.phonegap100.com/appapi.php",{
				params:{
					a:"getPortalArticle",
					aid:121,
					callback:"JSON_CALLBACK"
				}
			}).then(function(res){
				$rootScope.$broadcast("detail",res.data.result)
			})
		}
		
	}
}])
.service('luntan',['$rootScope','$http',function($rootScope,$http){
	return {
		fen:function(){
			$http.jsonp('http://www.phonegap100.com/appapi.php?a=getThreadCate',{
				params:{
					a:"getThreadCate",
					callback:"JSON_CALLBACK"
				}
			}).then(function(res){
				$rootScope.$broadcast('fen',res.data.result)
			},function(error){
				console.log(error)
			})
		},
		list:function(fid,num){
			$http.jsonp("http://www.phonegap100.com/appapi.php",{
				params:{
					a:"getThreadList",
					fid:fid,
					page:num,
					callback:"JSON_CALLBACK"
				}
			}).then(function(res){
				$rootScope.$broadcast('LuntanList',res.data.result)
			},function(error){
				console.log(error)
			})
		},
		detail:function(tid){
			$http.jsonp("http://www.phonegap100.com/appapi.php",{
				params:{
					a:"getThreadContent",
					tid:tid,
					callback:"JSON_CALLBACK"
				}
			}).then(function(res){
				$rootScope.$broadcast('detail',res.data.result)
			},function(error){
				console.log(error)
			})
		}
		
	}
}])
